package com.ruoyi.odorservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.odorservice.entity.Company;
import com.ruoyi.odorservice.model.bean.CompanyIndustryInfoBean;
import com.ruoyi.odorservice.model.bean.CompanyInfoListBean;
import com.ruoyi.odorservice.model.vo.CompanyListVo;
import com.ruoyi.odorservice.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/company")
@Api(tags = "企业信息")
@AllArgsConstructor
public class CompanyController {

    private CompanyService companyService;

    @PostMapping("/addCompany")
    @ApiOperation(value = "添加企业", httpMethod = "POST")
    public Result<Boolean> addCompany(@RequestBody CompanyIndustryInfoBean company) {
        if(company.getCompanyName() == null) return Result.fail("必要参数为空");
        return companyService.addCompany(company);
    }

    @PostMapping("/updateCompany")
    @ApiOperation(value = "修改企业信息", httpMethod = "POST")
    public Result<Boolean> updateCompany(@RequestBody CompanyIndustryInfoBean company) {
        if(company.getId() == null) return Result.fail("必要参数为空");
        if(company.getCompanyName() == null) return Result.fail("必要参数为空");
        return companyService.updateCompany(company);
    }

    @GetMapping("/list")
    @ApiOperation(value = "企业列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page" , value = "页码", paramType = "query", dataType = "Integer", required = false),
            @ApiImplicitParam(name = "limit" , value = "条数", paramType = "query", dataType = "Integer", required = false),
            @ApiImplicitParam(name = "companyName" , value = "企业名称", paramType = "query", dataType = "String", required = false)
    })
    public Result<Page<CompanyListVo>> companyList(Integer page, Integer limit, String companyName) {
        if(page == null) page = 1;
        if(limit == null) limit = 10000000;
        CompanyInfoListBean companyInfoListBean = new CompanyInfoListBean(page, limit, companyName);
        return companyService.companyList(companyInfoListBean);
    }

}
